<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <style>
        .box {
            width: 0;
            height: 0;
            border-right: 80px solid transparent;
            border-left: 80px solid transparent;
            border-top: 80px solid #d43131;
            border-bottom: 80px solid transparent;
        }
        #box2 {
            width: 300px;
            height: 300px;
        }
    </style>
</head>
<body>
    <div class="box"></div>
    <canvas id="box2"></canvas>
</body>
<script>
    const canvas = document.querySelector('#box2')
    const ctx = canvas.getContext('2d')
    ctx.beginPath()
    ctx.moveTo(0, 0);
    ctx.lineTo(100, 0);
    ctx.lineTo(0, 50);
    ctx.closePath(); //虽然我们只绘制了两条线段，但是closePath会closePath，仍然是一个3角形

    ctx.fillStyle="#8989e7";
    ctx.fill();
</script>
</html>
